package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.interceptor.LoginInterceptor;
import org.example.manager.DomainManager;
import org.example.mapper.DomainMapper;
import org.example.model.DomainDO;
import org.example.service.DomainService;
import org.example.vo.DomainVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ykc
 * @since 2025-03-09
 */
@Service
public class DomainServiceImpl implements DomainService {

    @Autowired
    private DomainManager domainManager;

    @Override
    public List<DomainVO> listAll() {

        Long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();

        List<DomainDO> customDomainList = domainManager.listCustomDomain(accountNo);
        List<DomainDO> officialDomainList = domainManager.listOfficialDomain();

        customDomainList.addAll(officialDomainList);

        return customDomainList.stream()
                .map(obj -> beanProcess(obj))
                .collect(Collectors.toList());
    }

    private DomainVO beanProcess(DomainDO domainDO) {

        DomainVO domainVO = new DomainVO();

        BeanUtils.copyProperties(domainDO, domainVO);

        return domainVO;
    }
}
